﻿ 
using SHKF.B2C.Erp.Model.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SHKF.B2C.Erp.BLL.WorkingCenter
{
    public class WorkingCenterBLL : BaseBLL
    {
        public WorkingCenterBLL(SqlSugarClient db) :base(db)
        { 
            base.db.ChangeDatabase("PtE_YZY_WorkingCenter");
        }

        /// <summary>
        /// 查询虚拟商店SN下的列表,默认升序
        /// </summary>
        /// <param name="ShopVSN"></param>
        /// <returns></returns>
        public List<ShopRelatedEntity> QueryShopRelated(int ShopVSN)
        {
            List<ShopRelatedEntity> list = this.db
                .Queryable<ShopRelatedEntity>()
                .Where(oo => oo.ShopVSN == ShopVSN)
                .OrderBy(o => o.OrderNumber)
                .ToList();
            return list;
        }

        /// <summary>
        /// 获取产品关系表
        /// </summary>
        /// <param name="ProductVSN"></param>
        /// <param name="WarehousSN"></param>
        /// <returns></returns>
        public List<ProductInfoRelatedEntity> QueryProductInfoRelated(long[] ProductVSN)
        {
            List<ProductInfoRelatedEntity> list = base.db
                .Queryable<ProductInfoRelatedEntity>()
                .Where(ww => ProductVSN.Contains(ww.ProductVSN))
                .ToList();

            //List<ProductInfoRelatedEntity> list = base.db
            //    .Queryable<ProductInfoRelatedEntity>()
            //    .Where(oo => oo.ProductVSN == ProductVSN)
            //    .ToList();
            return list;
        }

        /// <summary>
        /// 获取库存数
        /// </summary>
        /// <param name="ShopVSN"></param>
        /// <param name="WarehousSN"></param>
        /// <param name="ProductSN"></param>
        /// <returns></returns>
        public WareHouseDataEntity QueryWareHouseData(int ShopVSN, string WarehousSN, int ProductSN)
        {
            WareHouseDataEntity info = base.db
                .Queryable<WareHouseDataEntity>()
                .Where(oo => oo.ShopVSN == ShopVSN 
                                && oo.WarehousSN == WarehousSN 
                                && oo.ProductSN == ProductSN)
                .First();
            return info;
        }
    }
}
